from pyramid.config import Configurator
from sqlalchemy import engine_from_config

from cpswarehouse.models import initialize_sql


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    config = Configurator(settings=settings)

    config.add_static_view('static', 'cpswarehouse:static')
    
    config.add_route('index', '/')
    config.add_route('schools_on_a_map', '/on-a-map')
    config.add_route('school_listing', '/schools/')                    
    config.add_route('school_detail', '/schools/{school}')
    config.add_route('school_detail_by_year', '/schools/{school}/{year}')
    config.add_route('year_listing', '/years/')
    config.add_route('year_detail', '/years/{year}')
    config.add_route('what_is_this', '/about')
    config.add_route('dont_scrape_me', '/dont-scrape-me')
    config.add_route('get_involved', '/get-involved')
    config.add_route('tutorial', '/tutorial')

    config.scan('cpswarehouse')
    
    return config.make_wsgi_app()


